/**
 * 作者: wgx
 * 日期: 2025-04-29 10:56:22
 * 备注: 大世界事件配置表
 */
package com.motu.monstercity.server.game.commondata.world;
import com.motu.monstercity.server.game.base.CommonUtils;
import com.motu.monstercity.server.game.commondata.bag.BagConstant;
import com.motu.monstercity.server.game.commondata.bag.Box;
import com.motu.monstercity.server.game.logic.BagManager;
import com.motu.monstercity.server.game.logic.RewardItem;
import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.json.JsonObject;

import java.util.List;

public class WorldEvent extends WorldEventModel {
    public WorldEvent(JsonObject obj) {
        super(obj);
    }

    // 生成随机奖励
    public String takeRandomChip() {
        List<RewardItem> rewardItemList = CommonUtils.takeReawrdItemFromStr(getChipId());
        int size = rewardItemList.size();
        if (size == 0) {
            return "";
        }
        RewardItem rewardItem = rewardItemList.get(Tool.getIntRandom(size));
        if (rewardItem == null) {
            return "";
        } else {
            return CommonUtils.getRewardString(rewardItem);
        }
    }

    // 是否悬赏事件
    public boolean isOfferEvent() {
        return getType() == WorldConstant.WORLD_EVENT_TYPE_5;// 是否悬赏事件
    }

    // 是否采集事件
    public boolean isCollectionEvent() {
        return getType() == WorldConstant.WORLD_EVENT_TYPE_2;// 是否采集事件
    }

    // 生成全胜的宝箱随机奖励
    public String takeBoxReward() {
        if (getBoxId() == 0) {
            return "";
        }
        Box box = BagManager.getBox(getBoxId());
        if (box == null) {
            return "";
        }
        if (box.getType() != BagConstant.BOX_REWARD_TYPE_0 && box.getType() != BagConstant.BOX_REWARD_TYPE_1) {
            return "";
        }

        List<RewardItem> rewardItemList = BagManager.takeRewardFromBox(box, 1);
        int size = rewardItemList.size();
        if (size == 0) {
            return "";
        }
        return CommonUtils.getRewardString(rewardItemList);
    }
}
